import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter_reader/model/main/date_time_model.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_reader/tools/globals.dart' as globals;

const testURL = 'http://appapi.98nice.cn/api';

class MainDao{
  static Future fetchDateTime() async{
    Dio dio = Dio();
    final response = await dio.get(testURL+'/config/datetime',
      options: Options(headers: {
        'READING': 'API'
      }));
    if(response.statusCode == 200){
      return response.data;
    }
    else
    {
      throw Exception('加载dateTime接口失败');
    }
  }

  static Future getSessionID(String autographCode, int dateTime, String uuid) async{
    Dio dio = Dio();
    final response = await dio.post(testURL+'/login/guest',
        data: {
          'request_date':dateTime,
          'uuid':uuid
        },
        options: Options(
            contentType:Headers.formUrlEncodedContentType,
            headers: {
              'BSAppID':globals.appID,
              'BSAuthSign':autographCode,
              'READING':'API',
              'Content-Type':'application/x-www-form-urlencoded'}));
    if(response.statusCode == 200)
    {
      return response.data;
    }
    else
    {
      print(response.statusCode);
      throw Exception('加载getSessionID接口失败');
    }
  }
}